#include<iostream>
#include<algorithm>
using namespace std;

const int maxn=1e4+10;
int K;
int dp[maxn],Seq[maxn];

int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d",&K);
    for(int i=0;i<K;i++){
        scanf("%d",&Seq[i]);
    }
    dp[0]=Seq[0];
    bool flag=false;
    for(int i=0;i<K;i++){
        if(Seq[i]>=0) flag=true;
    }
    if(flag==false){printf("%d %d %d",0,Seq[0],Seq[K-1]);return 0;}
    for(int i=1;i<K;i++){
        dp[i]=max(Seq[i],dp[i-1]+Seq[i]);
    }
    int ans=0xc0c0c0c0,start=0,send=0;
     for(int i=0;i<K;i++){
         if(dp[i]>ans){
             ans=dp[i];
             send=i;
         }
     }
    if(send==0){printf("%d %d %d",ans,Seq[0],Seq[0]);return 0;}
    for(int i=send;i>0;i--){
        if(dp[i]!=dp[i-1]+Seq[i]){
            start=i;
            break;
        }
    }
    printf("%d %d %d",ans,Seq[start],Seq[send]);

}
